<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户列表</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		$(function(){
			// 用户角色列表
			$('#role').combobox({
				valueField:'dict_code',
				textField:'dict_name',
				url:'${pageContext.request.contextPath }/admin/user/findRoles'
				
			});
			$('#role').combobox("setValue","-1");
			loadTable();
			
		});
		
		function loadTable(){
			$('#dg').datagrid({
				rownumbers:true,
				singleSelect:true,
				pagination:true,
				pageSize:10,
				pageList:[10,20,30,50,100],
		 		url:'${pageContext.request.contextPath }/admin/user/listUserPage',
		 		queryParams:{
		 			 role:$('#role').combobox("getValue"),
		 			 username:$('#username').val(),
		 			 mobile:$('#mobile').val()
		 		},
	    		columns:[[
					{field:'userid',title:'编号',align:'center',width:45},
					{field:'cust_id',title:'客户编号',align:'center',width:60},
					{field:'username',title:'用户名',align:'center',width:70},
					{field:'sex',title:'性别',width:40,align:'center',formatter: function (value, row, index) {
						var status='';
						if(value==0)
							status="男";
						else if(value==1)
							status="女";
						return status;
					}},
					{field:'init_pass',title:'初始密码',align:'center',width:90},
					{field:'mobile',title:'手机号码',align:'center',width:100},
					{field:'qq',title:'QQ',width:100,align:'center'},
					{field:'wx',title:'微信',width:100,align:'center'},					
					{field:'enable',title:'用户状态',width:60,align:'center',formatter: function (value, row, index) {
						var status='';
						if(value==0)
							status="<span style='color:red;'>禁用</span>";
						else if(value==1)
							status="正常";
						return status;
					}},
					{field:'is_cancel',title:'是否删除',width:60,align:'center',formatter: function (value, row, index) {
						var status='';
						if(value==1)
							status="<span style='color:red;'>删除</span>";
						else if(value==0)
							status="正常";
						return status;
					}},
					{field:'dict_name',title:'用户角色',width:80,align:'center'},
					{field:'create_time',title:'创建日期',width:160,align:'center'},
					{field:'operation',title:'操作选项',width:300,align:'center',formatter: function (value, row, index) {
						var str = '<a href="javascript:edit('+row.userid+')" name="edit" class="easyui-linkbutton" ></a>';
						if(row.enable==0){
							str=str+' | <a href="javascript:changeEnable('+row.userid+',1,'+row.is_cancel+')" name="on_use"  class="easyui-linkbutton" ></a>';
						}else{
							str=str+' | <a href="javascript:changeEnable('+row.userid+',0,'+row.is_cancel+')" name="no_use" style="color:red" class="easyui-linkbutton" ></a>';
						}
						if(row.is_cancel==0){
							str=str+' | <a href="javascript:changeCancel('+row.userid+',1)" name="delPerson" style="color:red" class="easyui-linkbutton" ></a>';
						}else{
							str=str+' | <a href="javascript:changeCancel('+row.userid+',0)" name="addPerson"  class="easyui-linkbutton" ></a>';
						}						
						str=str+' | <a href="javascript:resetPass('+row.userid+')" name="resetPass"  class="easyui-linkbutton" ></a>';
						/*
						str=str+' | <a href="javascript:manage('+row.userid+')" name="manage"  class="easyui-linkbutton" ></a>';
						*/
						return str;
					}}
	 			]],
				onLoadSuccess:function(data){  
			        $("a[name='on_use']").linkbutton({text:'启用',plain:true,iconCls:'icon-my-enable'});
			        $("a[name='no_use']").linkbutton({text:'禁用',plain:true,iconCls:'icon-my-disable'});
			        $("a[name='edit']").linkbutton({text:'编辑',plain:true,iconCls:'icon-edit'});
			        $("a[name='delPerson']").linkbutton({text:'删除',plain:true,iconCls:'icon-person-remove'});  
			        $("a[name='addPerson']").linkbutton({text:'恢复',plain:true,iconCls:'icon-person-add'});  
			        $("a[name='manage']").linkbutton({text:'管理',plain:true,iconCls:'icon-my-manage'}); 
			        $("a[name='resetPass']").linkbutton({text:'重置密码',plain:true,iconCls:'icon-my-set'});   
				}
			});
		}
		
		function showClass(channelId){
			show("${pageContext.request.contextPath}/admin/channel/enterArticleclassList/"+channelId,"管理子栏目信息");
		}
		
		function edit(userid){
			show("${pageContext.request.contextPath}/admin/user/editBefore/"+userid,"修改用户信息");
			
		}
		// 重置密码功能，重置的密码为随机生成的6位数字
		function resetPass(userid){
			var pass=getRandomPass();
			$.post("${pageContext.request.contextPath}/admin/user/resetPass",{userid:userid,password:pass},
				function(data){
					if(data=="0"){
						$.messager.alert('系统消息','<span style=\"color:red;\">密码重置失败，请稍后再试！</span>');	 
					}else{
						$.messager.alert('系统消息','密码重置成功！<br/>重置后的密码为：'+pass);
						$('#dg').datagrid('reload'); 
					}
						
				},"text");
		}
		
		// 更改用户登录状态
		function changeEnable(userid,status,is_cancel){
			if(status==1 && is_cancel==1){
				$.messager.alert('系统消息','<span style=\"color:red;\">用户为删除状态，无法启用登录！</span>');
				return;	
			}
			$.post("${pageContext.request.contextPath}/admin/user/changeEnable",{userid:userid,status:status},
				function(data){
					if(data=="0"){
						$.messager.alert('系统消息','<span style=\"color:red;\">用户登录状态更新，请稍后再试！</span>');	 
					}else{
						$.messager.alert('系统消息','用户登录状态更新成功！');
						$('#dg').datagrid('reload'); 
					}
						
				},"text");
		}
		
		// 删除用户，更改用户状态
		function changeCancel(userid,status){
			$.post("${pageContext.request.contextPath}/admin/user/changeStatus",{userid:userid,status:status},
				function(data){
					if(data=="0"){
						$.messager.alert('系统消息','<span style=\"color:red;\">用户状态更新失败，请稍后再试！</span>');	 
					}else{
						$.messager.alert('系统消息','用户状态更新成功！');
						$('#dg').datagrid('reload'); 
					}
						
				},"text");
		}
		
		
		
		// 打开一个新的选项卡，并制定选项卡的名称
		function show(url,name){
			parent.window.addTab(name,url);
		}
		
		function show(url,name,icon){
			parent.window.addTab(name,url,icon);
		}
		
		function findData(){
			loadTable();
		}
		
		function doAddNotice(){
			show("${pageContext.request.contextPath}/admin/user/addBefore","新增用户信息","icon-my-add");
		}
		
		// 得到6位数字的随机密码
		function getRandomPass(){
			var pass="";
			for(var i=0;i<6;i++){
				pass=pass+Math.ceil(Math.random()*(10)-1);
			}
			return pass;
		}
	</script>
	<style type="text/css">
		body{
		font-family:'微软雅黑';}
	</style>
  </head>
  
  <body>
    <table id="dg" title="用户列表" style="width:1320px;height:455px" toolbar="#searchtool"></table>
    <div id="searchtool" style="padding:5px">  
       <span style="margin:0px 12px;">用户角色:</span><input id="role" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">用户名:</span><input id="username" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">手机号码:</span><input id="mobile" class="easyui-textbox" style="width:180px;height:26px"/> 
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100px;margin:0px 3px;">查询</a> 
       <a href="javascript:doAddNotice()" class="easyui-linkbutton" data-options="iconCls:'icon-person-add'" style="width:100px;margin:0px 3px;">新增用户</a> 
    </div>
  </body>
</html>
